capture log close
log using log_unemployment_2spe, replace text

****************************************************************************************************************
** 	TITLE:		unemployment_2spe_model                                                                       ** 	
**	DATA:       unemployment_2spe_model.dta                                                                   **
**	AUTHORS:    Review version                                                                                **
**  PAPER:      State-Level Forecasts for the 2020 U.S. Presidential Election: Tough Victory Ahead for Biden  **
**	DATE:		August 2020 					                                                              **	
**	VERSION:	Stata 16					                                                                  **	
****************************************************************************************************************

* Open the dataset

use "unemployment_2spe_model.dta", clear

* Version control

version 16.0


**********************************
** UNEMPLOYMENT RATE BY QUARTER **
**********************************

* First quarter state-level unemployment rate

gen q1 = (jan + feb + mar)/3

* Second quarter state-level unemployment rate

gen q2 = (apr + may + jun)/3

* Third quarter state-level unemployment rate

gen q3 = (jul + aug + sep)/3

* Fourth quarter state-level unemployment rate

gen q4 = (oct + nov + dec)/3


**********************************************************************************************************
** DIFFERENCE IN UNEMPLOYMENT RATE BETWEEN Q2 OF CURRENT ELECTION YEAR AND Q4 OF PREVIOUS ELECTION YEAR **
**********************************************************************************************************

gen diff = q2 - q4[id - 4] 

replace diff = . if year == 1976 | year == 1977 | year == 1978 | year == 1979


*******************************************
** DROP DUPLICATES AND NON-ELECTION YEAR **
*******************************************

duplicates tag state year, gen(dup)
duplicates drop state year, force
drop dup

drop if state == "United States"

keep if year == 1980 | year == 1984 | year == 1988 | year == 1992 | year == 1996 | year == 2000 | year == 2004 | year == 2008 | year == 2012 | year == 2016 | year == 2020

sort year state


********************
** CLOSE LOG FILE **
********************

log close